;Sorensen DCS600-1.7 dc power supply
;	Written and tested with specifically Sorensen DSC 600 V, 1.7 A power supply.
;   Probably can be made to work with other supplies in the DCS series with minor mods to this file.
;   Tested over serial port to Windows PC via USB to serial adapter.
;  1/3/23   Rev B   Added setup menu and TestController standard power supply interface
; 11/9/22   Rev A   Originate, get communication, logging working

;  Make sure to set the configuration DIP switches correctly.

; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html

#metadef
#idString SORENSEN, DCS600-1.7,
#name Sorensen DCS600-1.7
#handle DCS600V1_7A

#replaceText Main_MaxVoltage 600
#replaceText Main_MaxOVP 660
#replaceText Main_MaxCurrent 1.7

#metadef
#idString SORENSEN, DCS80-13,
#name Sorensen DCS80-13
#handle DCS80V13A

#replaceText Main_MaxVoltage 80
#replaceText Main_MaxOVP 88
#replaceText Main_MaxCurrent 13

#meta

#idString SORENSEN, DCS600-1.7,
#name Sorensen DCS600-1.7
#handle DCS60017
#port comfixedbaud
; Alternate port types: comnobaud or com, com lets the user define baudrate on the "Load devices" page
#baudrate 19200
#eol \r
#author gby
#notes Tested with Sorensen DSC 600 V, 1.7 A power supply specifically.  But with minor file modification probably would work with any Sorensen DCS series supply.

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6) 
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
#value Voltage V D3
#value Current I D3

; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; Number of returned values must match number of columns defined with #value
; This is a single line command
#askValues meas:volt?;meas:curr?

; Format of answer: f=float, u=remove trailing letters, x=skip, *=Zero upper case values if this value is 0
;#askValuesReadFormat 

; Accept this delay when reading values (seconds)
#readingDelay 2

; Mode change have a longer delay on reading values (seconds)
#modeChangeDelay 10


; String to ask about actual meter mode, it is mostly used for DMM's
; This is a single line command
;#askMode 


; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode 


; Prepare the meter to response to #askValues
;#prepareSample arm:sour imm;:arm:count 1;:trig:sour imm;:trig:count 1;:trig:samp:count 1;init

; Initial commands to meter when establishing connection, used to disable local control
;#initCmd  

; Final command to meter before breaking connection, used to restore local control
;#finalCmd 

; Used to turn output off for power supplies, generators and electronic loads
;#outputOff 
#outputOff OUTP:STAT OFF

;  **********  Generic Power Supply Interface  *******
;  Modeled after existing Keithley 2280 series power supply from 10/19/20
; Using multi-channel interface in scripts requires vars set for PS, PS:2 in scripts.
; For example:
;  =var PS1=getDevice("PS")
;  =var PS2=getDevice("PS:2")

#interfaceType PS PS:2

#interface setCHVoltage SOUR:VOLT (value)
#interface getCHVoltage SOUR:VOLT?
;:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setCHCurrent SOUR:CURR (value)
#interface getCurrent SOUR:CURR?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOVP SOUR:VOLT:PROT (value)
#interface getOVP SOUR:VOLT:PROT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

;  This supply does not seem to have over current trip
;#interface setOCP SOUR:CURR:PROT (value)
;#interface getOCP SOUR:CURR:PROT?
;:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOn OUTP:STAT (value)
#interface getOn OUTP:STAT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

;#interface SetTripReset TRIPRST

;  Pull values from #askValues used for logging.  Index goes 0 to n.
#interface readCH1Voltage 0
#interface readCH1Current 1


;  Setup popup

; Settings Tab
#cmdSetup number Main_Voltage Settings
:read: SOUR:VOLT?
:write: SOUR:VOLT
Vdc  0 Main_MaxVoltage

#cmdSetup number Main_Current Settings
:read: SOUR:CURR?
:write: SOUR:CURR
Adc  0 Main_MaxCurrent

; Protection/limit Tab
#cmdSetup number Main_OVP Protect
;  Supply limits OVP to be at least 105% of actual voltage.
;  Symmetrically limits the main voltage set point to < OVP/1.05
:read: SOUR:VOLT:PROT?
:write: SOUR:VOLT:PROT
Vdc  0 Main_MaxOVP

;  DCS does not seem to have over current trip
;#cmdSetup number Main_OCP Protect
;:read: SOUR:CURR:PROT?
;:write: SOUR:CURR:PROT
;Adc  0 Main_MaxCurrent

; Could not find a way to reset a trip.
; Button to reset protection shut down
;#cmdSetup button Clear_Alarms Protect
;:write: OUTP:PROT:CLE
;:tip: Clear any active alarms

; Buttons to turn outputs on/off common to all tabs

#cmdSetup buttonsOn Main_Output
:string:
:read: OUTP:STAT?
:readmath: getElement("Off On",value);
:write: OUTP:STAT
:color: (0,255,0)
:tip: Turn Main output on or off
:updatealloff:
Off Off
On On




